<?php
class Manage_user_model extends CI_Model {

    public function __construct()
    {
        $this->load->database();
    }

    public function display_user_account($limit, $start, $user)
    {

        $this->db->select ('*');
        $this->db->from   ('user_accounts');
        $this->db->join   ('user_profile', 'user_profile.user_id = user_accounts.user_id');
        $this->db->join   ('user_col', 'user_col.coll_id = user_accounts.coll_id');
        $this->db->join   ('user_type', 'user_type.type_no = user_accounts.type_no');
        $this->db->order_by('coll_name asc, fname asc, user_type.type_no desc');
        $this->db->limit  ($limit, $start);
        $this->db->where  ('user_accounts.type_no !=', "0");
        $this->db->where  ('user_accounts.user_id !=', $user);

        $query = $this->db->get();

        return $query->result_array();

    }

    public function display_user_account_($limit,$start)
    {

        $this->db->select ('*');
        $this->db->from   ('user_accounts');
        $this->db->join   ('user_profile', 'user_profile.user_id = user_accounts.user_id');
        $this->db->join   ('user_col', 'user_col.coll_id = user_accounts.coll_id');
        $this->db->join   ('user_type', 'user_type.type_no = user_accounts.type_no');
        $this->db->order_by('fname', 'asc');
        $this->db->limit  ($limit, $start);

        $query = $this->db->get();

        return $query->result_array();

    }

    public function display_user_profile()
    {

        $this->db->select ('*');
        $this->db->from   ('user_profile');

        $query = $this->db->get();

        return $query->result();

    }

    public function display_user_college()
    {

        $this->db->select ('*');
        $this->db->from   ('user_col');
        $this->db->where   ('coll_id !=', 0);

        $query = $this->db->get();

        return $query->result();

    }

    public function display_user_type()
    {

        $this->db->select ('*');
        $this->db->from   ('user_type');
        $this->db->where  ('name_type !=','Administrator');
        $this->db->where  ('name_type !=','Uncategorized');
        $this->db->where  ('name_type !=','Dean');

        $query = $this->db->get();

        return $query->result();

    }

    public function check_acc($username)
    {

        $this->db->select ('*');
        $this->db->from   ('user_accounts');
        $this->db->where  ('user_id', $username);

        $query = $this->db->get();

        if($query->num_rows() == 1)
            return $query->result();
        else
            return false;

    }

    public function insert_data($input1, $input2, $input3){

        $this->db->insert ('user_accounts',$input1);
        $this->db->insert ('user_profile',$input2);
        $this->db->insert ('user_img',$input3);

    }

    public function delete_data($data){



        $this->db->delete('user_accounts', array('user_id' => $data));

    }

    public function check_college($id){

        $this->db->select   ('*');
        $this->db->from     ('user_col');
        $this->db->where     ('coll_id', $id);

        $query = $this->db->get();

        return $query->result_array();

    }

}